package ecom.stateless;

import java.security.Principal;
import javax.annotation.Resource;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;

import ecom.api.*;

@Stateless(mappedName = "ecom.TestGetIdentifier@Remote", description = "Client TestGetIdentifier stateless", name = "TestGetIdentifier")
public class TestGetIdentifier implements ITestGetIdentifier{

	String user;

	@Resource
	private SessionContext sctxt;
	
	
	public String getUserName()
	{
		try {
			if(sctxt!=null)
			{
			Principal principal = sctxt.getCallerPrincipal();
			if (principal!=null) {
				String aux = principal.getName();
				if (aux == null)
					user = new String("princNULL");
				else
					user = new String(aux);
			}
			else user = new String("null principal");
			} else user= new String("null context");
		} catch (Exception e) {
			user = new String("except " + e.getMessage());
			return user;
		}
		
		return user;
	}
	

}
